package top.ewind.plugin;

import java.io.IOException;

import io.moquette.server.Server;
import io.moquette.server.config.ClasspathResourceLoader;
import io.moquette.server.config.IConfig;
import io.moquette.server.config.IResourceLoader;
import io.moquette.server.config.ResourceLoaderConfig;

import com.jfinal.plugin.IPlugin;

public class MqttPlugin implements IPlugin {

	private static Server mqttBroker;

	public boolean start() {
        IResourceLoader classpathLoader = new ClasspathResourceLoader();
        final IConfig classPathConfig = new ResourceLoaderConfig(classpathLoader);
		mqttBroker = new Server();
		try {
			mqttBroker.startServer(classPathConfig);
			return true;
		} catch (IOException e) {
			return false;
		}
	}

	public boolean stop() {
		mqttBroker.stopServer();
		return true;
	}

}